package cn.jeefast.rest.controller;


import cn.jeefast.common.utils.R;
import cn.jeefast.rest.annotation.AuthIgnore;
import cn.jeefast.rest.entity.TbUser;
import cn.jeefast.rest.service.MbDoctorService;
import cn.jeefast.rest.service.TbUserService;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author theodo
 * @since 2019-12-30
 */
@RestController
@RequestMapping("/api")
public class MbDoctorController {

    @Autowired
    private TbUserService tbUserService;

    @Autowired
    private MbDoctorService doctorService;

    /**
     * 医生注册
     * @return
     */
    @RequestMapping("/doctor/register")
    @AuthIgnore
    @CrossOrigin
	public R register(TbUser user){
        user.setPassword("123456");
        user.setPassword(DigestUtils.sha256Hex(user.getPassword()));
        user.setCreateTime(new Date());
        tbUserService.insert(user);
	    return R.ok();
    }

    /**
     * 医生登录
     * @return
     */
    @RequestMapping("/doctor/login")
    @AuthIgnore
    public R login(String mobile,String pssword){
        long login = tbUserService.login(mobile, pssword);
        return R.ok("").put("data",null);
    }

    /**
     * 医生个人信息
     * @param docId
     * @return
     */
    @RequestMapping("/doctor/info")
    public R homePage(Long docId){
        return doctorService.homePage(docId);
    }
}